package com.company;

/**
 * @author jrue
 * @version 1.0
 * @date 2020/3/22 18:54
 */
public class Main41 {

    public static void main(String[] args) {
        int[] ints = DistanceToHigher(new int[]{175, 173, 174, 163, 182, 177});
        for (int i = 0; i < ints.length; i++) {
            System.out.print(ints[i] + " ");
        }
    }

    public static int[] DistanceToHigher (int[] height) {
        // write code here
        final int length = height.length;
        int[] dp = new int[length];
        dp[0] = 0;
        for (int i = 1; i < dp.length; i++) {
            if (height[i - 1] > height[i]) dp[i] = 1;
            else {
                boolean flag = false;
                int lastIndex = 0;
                for (int j = i - 1; j >= 0 ; j--) {
                    if (height[i] < height[j]) {
                        flag = true;
                        lastIndex = j;
                    }
                }
                if (flag) {
                    dp[i] = i - lastIndex;
                } else {
                    dp[i] = 0;
                }
            }
        }
        return dp;
    }

}
